Skip to content

Abort render when state setter is called during render#64

Merged
L3P3 merged 5 commits intomasterfrom
copilot/abort-render-on-state-change
Mar 4, 2026
Merged

Abort render when state setter is called during render#64
L3P3 merged 5 commits intomasterfrom
copilot/abort-render-on-state-change

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

  • In hook_state setter: throw dom_cache when state is set during rendering of the same component
  • In hook_model mutation setters: same throw logic
  • In instance_render catch block: detect the abort (instance.dirty=true) and return early (bail out)
  • In hook_sub catch block: rethrow dom_cache when instance is dirty (propagate abort upward)
  • In hook_map catch block: rethrow dom_cache when instance is dirty (propagate abort upward)
  • Add test for abort-render-on-state-change behavior
  • Increment version patch digit (2.3.0 → 2.3.1)
  • Merge two if blocks in hook_sub and hook_map catch blocks using trailing ||
  • Format if conditions in 3-line style in hook_state and hook_model setters
  • Improve test: add after_set_count counter to verify code past the setter only runs once
Original prompt

This section details on the original issue you should resolve

<issue_title>Abort render when re-render is requested during render</issue_title>
<issue_description>Example:

const [value, value_set] = hook_state(false);
if (some_condition) value_set(false);
...

The ... part would not need to be evaluated at this point since the value_set will cause this component body to be ran again anyways. It should be safe to just abort the render altogether when causing a state change.

Currently, hook_assert uses a similar strategy to not render components.
Find some other object we can re-use as an abort signal and throw that in hook_state and other setters. But only do that when the currently rendered component is the one the hook was used in.

In the render function's catch block, detect this signal and just bail out or even directly tail-call so we can re-render without waiting for the queue.</issue_description>

<agent_instructions>At the end, increment the version patch digit.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…to 2.3.1

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix abort render when re-render is requested during render Abort render when state setter is called during render Mar 4, 2026
Copilot finished work on behalf of L3P3 March 4, 2026 15:45
@L3P3 L3P3 marked this pull request as ready for review March 4, 2026 16:23
Copilot AI review requested due to automatic review settings March 4, 2026 16:23
…est counter

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an early-abort optimization to stop executing the remainder of a component render when a state/model setter schedules a rerender during that same render pass, reusing the existing dom_cache sentinel and relying on instance.dirty to distinguish abort types.

Changes:

  • Throw dom_cache from hook_state / hook_model setters when invoked during the owning component’s render, to abort wasted work.
  • In instance_render, return early on catching the sentinel when instance.dirty indicates a rerender has already been queued.
  • Adjust hook_sub / hook_map to propagate the abort sentinel upward instead of swallowing it; bump version to 2.3.1; add a test for hook_state abort behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
src/lui.js Implements the render-abort mechanism across instance_render, hook_state, hook_model, hook_sub, and hook_map.
test/hook-state.test.js Adds a regression test for abort + immediate rerender when a state setter is called during render.
package.json Bumps patch version 2.3.02.3.1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copilot finished work on behalf of L3P3 March 4, 2026 16:32
@L3P3 L3P3 merged commit 40f5d9c into master Mar 4, 2026
3 checks passed
@L3P3 L3P3 deleted the copilot/abort-render-on-state-change branch March 4, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Abort render when re-render is requested during render

3 participants